package com.frkj.yuan.fragment.my;
import android.content.SharedPreferences;

import androidx.recyclerview.widget.RecyclerView;

import com.frkj.yuan.R;
import com.frkj.yuan.adapter.BaseRecyclerHolder;
import com.frkj.yuan.adapter.BaseRecyclerRefreshAdapter;
import com.frkj.yuan.api.bean.CouponsListBean;
import com.frkj.yuan.api.category.CouponsCategory;
import com.frkj.yuan.api.presenter.CouponsPresenter;
import com.frkj.yuan.base.BaseFragment;
import com.frkj.yuan.data.YuyueKeshiDataUtils;
import com.frkj.yuan.main.ConstantStaticUrl;
import com.frkj.yuan.utils.HttpNetworkConnectUtils;
import com.frkj.yuan.utils.SPUtils;
import com.frkj.yuan.utils.ToastUtil;
import com.frkj.yuan.view.RecyclerViewLayoutManager;

import java.io.IOException;
import java.util.List;

import butterknife.BindView;

import static android.content.Context.MODE_PRIVATE;

/**
 * 信息说明: 没有使用
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/7 10 ：39
 * 项目名称：yuanban
 */
public class CouponsNotUsedFragment extends BaseFragment implements CouponsCategory.View {
    @BindView(R.id.base_recycler)
    RecyclerView mRecyclerView ;
    private CouponsPresenter mPresenter;
    private int pageNumber = 1;
    private String mToken;
    private long mUserId;
    @Override
    public int getLayoutResource() {
        return R.layout.base_recycler_view;
    }
    @Override
    public void initLayoutView() {
        RecyclerViewLayoutManager.setLinearVerticalManager(getActivity(),mRecyclerView);
        mToken = (String) SPUtils.get(getActivity(), ConstantStaticUrl.mToken,"");
        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("First", MODE_PRIVATE);
        mUserId = sharedPreferences.getLong(ConstantStaticUrl.userId, 0);
        mPresenter = new CouponsPresenter(this);
        SetPersenter(mPresenter);
        if (!HttpNetworkConnectUtils.isNetworkConnected(getActivity())){
            ToastUtil.showToastINFO(getActivity(),"网络未连接，请打开网络");
        }else {
            mPresenter.getYouhuiQuanList(pageNumber,mToken,mUserId,1);
        }
    }
    @Override
    public void getYouhuiQuanList(CouponsListBean couponBean) {
        if (couponBean.getCode()==ConstantStaticUrl.SUCCESS_CODE){
            mRecyclerView.setAdapter(new BaseRecyclerRefreshAdapter<CouponsListBean.CouponsListBeanData.CouponsListBeanDataList>(getActivity(), couponBean.getData().getList(), R.layout.not_user_coups) {
                @Override
                public void convert(BaseRecyclerHolder holder, CouponsListBean.CouponsListBeanData.CouponsListBeanDataList item, int position, boolean isScrolling) throws IOException {
                    holder.setText(R.id.coup_name,item.getName());
                    holder.setText(R.id.coup_price,String.valueOf(item.getMinus()));
                    holder.setText(R.id.coup_time,item.getExpiredTime());
                }
            });
        }
    }
    @Override
    public void SetPersenter(Object persenter) {}
    @Override
    public void OnShowErrorMsg(String mErrorMsg) {}
}
